package com.nettylearning.base.netty.io.channel;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author vince
 * @date 2021/7/21 8:54
 * @Version 1.0
 */
public class FileInputDemo {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = new FileInputStream("D://test.txt");

        // 从FileInputStream 获取Channel
        FileChannel fc = fileInputStream.getChannel();

        // 创建Buffer
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        // 将数据从Channel写入Buffer
        fc.read(buffer);
        buffer.flip();

        while (buffer.remaining() > 0) {
            byte b = buffer.get();
            System.out.println((char) b);
        }

        fileInputStream.close();
    }
}
